<?php 
session_start();
include '../connection/connection.php';
				
if(isset($_REQUEST['action'])){
	if($_REQUEST['action']=="editLicense"){
		$email=$_REQUEST['email'];
		$max_server=$_REQUEST['max_server'];
		mysql_query("UPDATE user_info SET max_server='$max_server' WHERE (email='$email')");
	}
}
				$lang=$_SESSION['lang'];
				if($lang=='')
						$lang='EN';
				
				if ( !isset($_REQUEST['page'] ))
				{
			    	$page = 1 ;
				}else{
					$page = $_REQUEST['page'] ;
				}
				
				function getlang(){
					$lang = $_SESSION['lang'];
					if (empty($lang) || $lang == "KR") {
						$value = "../value/value_kr.php";
					} else if($lang == "VN") {
						$value = "../value/value_vn.php";
					}
					else if($lang == "EN"){
						$value = "../value/value_en.php";
					}
					return $value;
				}
				
				$value = getlang();
				include($value);
							
				$rows_per_page = 20;
				$page_start = ( $page - 1 ) * $rows_per_page; 
				$page_end = $page * $rows_per_page;
				
			
    			$query=mysql_query("SELECT * FROM log_buy b,user_info u WHERE b.email=u.email AND u.role=0;");
    			
    			$number_of_page = ceil ( mysql_num_rows( $query ) / $rows_per_page ); 
				 $list_license=array();
				 $email_temp="";
				 $co=0;
				
			?>
			
	       <table width="900" cellpadding="0" cellspacing="0" class="mtable">
	    	<thead>
	        	<tr>
	        		<td align="left" style="width: 3%"><?php echo $no?></td>
	                <td align="center"><?=$address_email?></td>
	                <td align="center"><?=$buy_date?></td>
	                <td align="center"><?=$type_license?></td>
	                <td align="center"><?=$date_start?></td>
	                <td align="center"><?=$date_stop?></td>
	                <td align="center"><?=$license_count?></td>
	                <td align="center">max server</td>
	            </tr>
	        </thead>
	       <?php 
	       $i=1;
	        while ($row=mysql_fetch_array($query)){
	        			
	        			if($row['buy_type']==1){
	        				$buy_type=$free;
	        				$color='#E2EFF8';
	        			}else {
	        				$buy_type=$money;
	        				$color='#F7EAE8';
	        			}
	        			$color="white";
	        			if ( $i > $page_start ){
	        		?>
		        <tr>
		        	<td align="left"  style="width: 3%"><?=$i?></td>
	        		<td><a href="#?w=400" style="color: blue" onclick="calleditLicense('<?=$row['email']?>','<?=$row['date_start']?>','<?=$row['date_stop']?>','<?=$row['license_count']?>','<?=$row['max_server']?>','<?=$page?>',this)" rel="popup_name" class="poplight"><?=$row['email']?></a></td>
	        		<td align="center"><?=$row['buy_date']?></td>
	        		<td align="center"><?=$buy_type?></td>
            		<td align="center"><?=$row['date_start']?></td>
            		<td align="center"><?=$row['date_stop']?></td>
            		<td align="center"><?=$row['license_count']?></td>
            		<td align="center"><?=$row['max_server']?></td>
		        </tr>
		      <?php 
	        			
					
						if ($i >= $page_end){
							break;
						}
	        			}
	        			$i++;
	        } 
	        
			mysql_close($connection);	 
		
	        	?>
	        	<tr>
						<td colspan="9" class="rf-dt-shdr-c">
							<span style="padding:1px; display: inline-block;">
														
								<?php if ( $number_of_page > 1 ) 
								{ 
									if ($page==1)
										$p=2;
									else if ($page==$number_of_page)
										$p=$number_of_page-1;
									else $p=$page;
									if($page!=1){?>
										<a onclick="paging(<?=1?>)" ><span class='button_next'><?php echo "<<<";?></span> </a>
										<a onclick="paging(<?=($page-1)?>)"><span class='button_next'><?php echo "<<";?></span> </a>
									<?php  }
									else{
										echo "<span class='button_next'><<<</span> "; 
										echo "<span class='button_next'><<</span> ";
									}
									for ( $i = $p-1; $i <= $p+1; $i++ ) {	
											if ($i<=$number_of_page && $i>0)
											
												if ($i==$page){
													echo "<span class='button_next'><b>".$i."</b></span>"; 
												}else{
												?>
													<a onclick="paging(<?=$i?>)"><span class="button_next">
													<?php 
													echo $i;
													?>
													</span> </a>
													<?php 
												}
											?>
										
									<?php 
											}
										
										if($page!=$number_of_page){ ?>
											<a onclick="paging(<?=($page+1)?>)"><span class='button_next'><?php echo ">>";?></span> </a>
											<a onclick="paging(<?=($number_of_page)?>)"><span class='button_next'><?php echo ">>>";?></span> </a>
										<?php }
										else{
											echo "<span class='button_next'>>></span> ";
											echo "<span class='button_next'>>>></span> ";
										}
									}
								
									
									?>
																						
							</span>
						</td>
					</tr>
	    </table>